import { Controller,Post,Get,HttpStatus,SetHeader,Next,Session,Query,Body,Param,Header,Ctx } from '@/decorator'

const requiredFn = value => {
  console.log(`required fn on value ${ value }`)
}

@Controller('/login')
class Login{
  @Get('/string')
  @HttpStatus(200)
  @SetHeader({ 'aa':'bb','cc': 'dd','token': '234434434dadgad' })
  async getString(
    @Next next,
    @Query('id') id: string,
    @Session.required('user') user: string,
    @Query.required('name') name: string,
    @Query.required('age',requiredFn) age: string | number,
    @Query('job') job: string,
    @Body('json') json: {},
    @Query('aaf') aaf: string,
  ){
    return {
      code: true,
      text: '/login/string',
      data: {
        query: { id,name,age,job,aaf },
        body: { ...json },
        session: { user }
      }
    }
  }
  @Post('/post/:type/:user')
  async setPost(
    @Param.required('type') type: string,
    @Param('user') user: string,
    @Query.required('id') id: string,
    @Query('name') name: string,
    @Query('age') age: string | number,
    @Query('job') job: string,
    @Body.required('json') json: {},
    @Query('aaf') aaf: string,
    @Header.required('token') token: string,
    @Header.required('social-token') social: string
  ){
    return {
      text: `/login/post/${ type }/${ user }?id=${ id }&name=${ name }&age=${ age }&job=${ job }&aaf=${ aaf }`,
      query: { id,name,age,job,aaf },
      body: { json },
      params: { type,user },
      headers: { token,social }
    }
  }
  @Get('/haha')
  async getPost(
    @Query('id') id: string,
    @Query('name') name: string,
    @Query('age') age: string | number,
    @Query('job') job: string
  ){
    return {
      text: '/login/string => hello word',
      data: {
        age,job,id,name
      }
    }
  }
}

export default Login
